package com.fyzk.activity.user.jczq_sp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tyjc.lottery.R;
import com.fyzk.model.Ticketlist;

import java.util.ArrayList;

public class JCZQSPListAdapter extends BaseAdapter{

	private ArrayList<Ticketlist> infos;
	private Context context;

	public JCZQSPListAdapter(Context context, ArrayList<Ticketlist> infos) {
		// TODO Auto-generated constructor stub
		this.context = context;
		this.infos = infos;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.jczqsp_listview, null);
			holder.team1_week = (TextView) convertView.findViewById(R.id.jczqsp_listview_team1_week);
			holder.team1_bet = (TextView) convertView.findViewById(R.id.jczqsp_listview_team1_bet);
			holder.team2_week = (TextView) convertView.findViewById(R.id.jczqsp_listview_team2_week);
			holder.team2_bet = (TextView) convertView.findViewById(R.id.jczqsp_listview_team2_bet);
			holder.chuan = (TextView) convertView.findViewById(R.id.jczqsp_listview_chuan);
			holder.zhu = (TextView) convertView.findViewById(R.id.jczqsp_listview_zhu);
			holder.bei = (TextView) convertView.findViewById(R.id.jczqsp_listview_bei);
			holder.state = (TextView) convertView.findViewById(R.id.jczqsp_listview_state);
			holder.prize = (TextView) convertView.findViewById(R.id.jczqsp_listview_prize_state);
			
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		try {
			Ticketlist info = infos.get(position);
			holder.zhu.setText(info.zhushu+"注");
			holder.bei.setText(info.multiple+"倍");
			holder.state.setText(info.ticketstate);
			holder.prize.setText("奖金:"+info.prize+"米");
			
			holder.team1_week.setText(info.tickets.get(0).week+" "+info.tickets.get(0).matchnum.substring(8, 11));
			String bet1 = "";
			if (!info.tickets.get(0).ticketbet_3.equals("")) {
				bet1 += "胜("+info.tickets.get(0).ticketbet_3+")\n";
			}
			if (!info.tickets.get(0).ticketbet_1.equals("")) {
				bet1 += "平("+info.tickets.get(0).ticketbet_1+")\n";
			}
			if (!info.tickets.get(0).ticketbet_0.equals("")) {
				bet1 += "负("+info.tickets.get(0).ticketbet_0+")";
			}
			holder.team1_bet.setText(bet1);
			
			holder.team2_week.setText(info.tickets.get(1).week+" "+info.tickets.get(1).matchnum.substring(8, 11));
			String bet2 = "";
			if (!info.tickets.get(1).ticketbet_3.equals("")) {
				bet2 += "胜("+info.tickets.get(1).ticketbet_3+")\n";
			}
			if (!info.tickets.get(1).ticketbet_1.equals("")) {
				bet2 += "平("+info.tickets.get(1).ticketbet_1+")\n";
			}
			if (!info.tickets.get(1).ticketbet_0.equals("")) {
				bet2 += "负("+info.tickets.get(1).ticketbet_0+")";
			}
			holder.team2_bet.setText(bet2);
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		
		
		return convertView;
	}
	class ViewHolder {
		TextView team1_week;
		TextView team1_bet;
		TextView team2_week;
		TextView team2_bet;
		TextView chuan;
		TextView zhu;
		TextView bei;
		TextView state;
		TextView prize;
	}
	
}
